package com.clarte.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class Rights implements Serializable {
	private static final long serialVersionUID = 8127565543176213715L;
	@Id
	@GeneratedValue
	private Integer id;
	private String name;
	private String url;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="p_id")
	private Rights parent;
	@OneToMany(mappedBy="parent")
	@Fetch(FetchMode.SUBSELECT)
	private Set<Rights> subRights;
	@ManyToMany(mappedBy="rights")
	@Fetch(FetchMode.SUBSELECT)
	private Set<Role> roles;
	
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public Rights getParent() {
		return parent;
	}
	public void setParent(Rights parent) {
		this.parent = parent;
	}
	public Set<Rights> getSubRights() {
		return subRights;
	}
	public void setSubRights(Set<Rights> subRights) {
		this.subRights = subRights;
	}
}
